package com.lanou.dllo.baisibudejie.fragment;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.lanou.dllo.baisibudejie.adapater.CardAdapter;
import com.lanou.dllo.baisibudejie.R;

/**
 * Created by dllo on 15/10/22.
 */
public class CardFragment extends Fragment {

    private TabLayout tabLayout;
    private ViewPager viewPager;
    private CardAdapter adapter;


    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
    }


    /**
     * 在这个方法里面，获取传入的数据
     *
     * @param savedInstanceState
     */
    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }


    /**
     * 这个方法里面加载布局
     */
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragmengt_card, null);

        return view;
    }


    /**
     * 控件初始化在这写
     */
    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);


        tabLayout = (TabLayout) view.findViewById(R.id.tabLayout);
        tabLayout.setSelectedTabIndicatorColor(0xff0088ff);
        tabLayout.setTabMode(TabLayout.MODE_FIXED);
        tabLayout.setTabGravity(TabLayout.GRAVITY_FILL);


        viewPager = (ViewPager) view.findViewById(R.id.viewPager);


    }


    /**
     * 数据初始化在这写
     *
     * @param savedInstanceState
     */
    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);

        //        CardAdapater adapter = new CardAdapater(getSupportFragmentManager());
        adapter = new CardAdapter(getActivity().getSupportFragmentManager());

        viewPager.setAdapter(adapter);
        //TabLayout和ViewPager进行绑定
        tabLayout.setupWithViewPager(viewPager);


    }


}
